var sign;
const fs = require('fs');
const {JSDOM} = require('jsdom');
const htmlContent = fs.readFileSync(`./run.html`, "utf8");
!(() => {
    "use strict";
    const $toString = Function.toString;  //hook Function.toString 且命名为myToString
    //变量名取随机数防检测
    const myFunction_toString_symbol = Symbol('('.concat('', ')_', (Math.random() + '').toString(36)));
    const myToString = function () {
        return typeof this == 'function' && this[myFunction_toString_symbol] || $toString.call(this);   //谁调用这个方法,this就是谁,比如boda调用,这个this就是boda
    };

    function set_native(func, key, value) {
        //定义描述符
        Object.defineProperty(func, key, {
            "enumerable": false,
            "configurable": true,
            "writable": true,
            "value": value
        })
    };
    delete Function.prototype['toString']; //删除原型链上的toString
    set_native(Function.prototype, "toString", myToString); //自己定义个getter方法
    //myToString的 myFunction_toString_symbol属性设置为  function toString() { [native code] }
    //myFunction_toString_symbol= function toString() { [native code] }
    set_native(Function.prototype.toString, myFunction_toString_symbol, "function toString() { [native code] }"); //套个娃 保护一下我们定义的toString 否则就暴露了
    globalThis.safefunction = (func, name) => {
        set_native(func, myFunction_toString_symbol, `function ${myFunction_toString_symbol, name || ''}() { [native code] }`);
        set_native(func, 'name', `${myFunction_toString_symbol, name || ''}`);
        // }
    }; //导出函数到globalThis
}).call(this);
const dom = new JSDOM(htmlContent, {
    url: "https://sg.xiapibuy.com/",		// 网站url，手动修改
    referrer: 'https://sg.xiapibuy.com/verify/traffic?signature=46de1b505e8ddc2bccf0f28d281dd8d1eda8b775b9399ed3fb287431d9b30bfce2515fb05547c8dd9cb56c3e7066d971314deece91d6e55c0b615f039fbd5b2e92d9843cff8765d2483dcf476395dbfdb2dfb626c138145d8a0825dfe587f431fa0507337fa387a3dae0810cc775ee2d1c6779c659045ea4481cc54791a62b190d798971e2682d477074fdc1dfe07d12209c01dbda61a3ab4f24991ed43ec5051e1dc18d61eab408d5e1948a5bde7da46c7555f3924d637f2d88908a5044af85ca0611397828269fe90bbffbaac5b8af28cf133a391cd790019c2553f9a8a6f03cbb3aada619e3a7062923b7b46bee0b1bfe8760b8730abf2c08821a1882f18c473435c9d774d67bf6c3f421045781438740d05a0ebf7c6d1ab2813ce342285e82ac88ab935737e602fa91b20757a824454aee47cde68ebc95f8ff44d37eb3496a5bd67dfaf1564e38ca42b4ca517b6b26c1ac53322e8aa37e2174805ac851f3e452de49f23e90547189fc7bef8a8a4f83c3c41b6bfbb00296f61f795b33232cd0cab137da1db661eda915749a0a1b001ec8e7db9f0cd91cc4cf825d7350f0ee970fbb3f8c7ad52b7773faa3cfb9d2425b8e8cf1388f5b67e70569130f34d576dfe85fba1519808f9c8662c07a16ede4e7b153a4097b3d6933de1d3e3f669a342c7231d8ad6501e7ccb6e64a18cbe84372ee9bca09bca6bf99ac1a777d51366944e27116ea8359df062001473182f97a7d76b888211facefced4dfa7d75b1d8553958e17297e65ccf02e79485df2a665d68a7e374d48d5af0053bd24cca93bdceb5a121559e14ac70a54a14d83b6dd0a7c7622708389e32d9a48da58b3c5f0b78ff6f205735bd5df56eb726834ec31429ac93a1dbfbf5c810724529448ceac90f6fa365c1a6f8c954790800acbca32f0618be7605c7918001ab3483819b7097458fc53103af1d4c969310e6bdd80efeb03023c6b16ed1fa82ea9d800a721f4443538e90d4b3c805f3541d4fa76f549ff1547264e96e77a5884335c05908ea395d7e5c937953f38ce4ff2752befeccde862a632be0379130dd5a8538a36533251572bb366b7d34b7434d97c34c5c876bc647f450ef6fec464ef349c61dc9f6db9f4e7fc9d252aed12dfb115418f383abcb3a25a8622d04a5fd4fb56ad3d358e42d2fc28674c744259ee3b097fd19e9f61b81329bd9e8b460752844a26712b1d75a9469bc7331414fb2cc73bbaae2ca1c09047628715bebc8c30c1ebf09e741421109c1b248bc15c83cf1ed6f32791dd4707cdf89d377b0b5120c8b8602dc07929cd13c0e69d680c6acbc9267ed81aafade8dadd8f5f2cbbd1576b5faf44c6c088cf29a90cb80a17809a5b11eb67296c0d52420b9720a4057deae58f60042394560e623f6de939d12ec23b49bba37424df174ebd867f0e519ca97614f6219a1c7cab17d2df372d9881326c29700762d80888e3387583a92bd1f95ea355e0',
    resources: 'usable',  // 启用外部资源加载
    runScripts: "outside-only",  // 不允许执行页面中的 JavaScript
    pretendToBeVisual: false, //  CSS 计算。
    userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0',
    resourceLoader: (url, callback) => callback(null, null)  // 禁用资源加载
});
delete process
window = globalThis
document = dom.window.document
screen = {}
navigator = {}
history = {}
location = dom.window.location
function get_enviroment(proxy_array) {
    for (var i = 0; i < proxy_array.length; i++) {
        handler = '{\n' +
            '    get: function(target, property, receiver) {\n' +
            '        console.log("方法:", "get  ", "对象:", ' +
            '"' + proxy_array[i] + '" ,' +
            '"  属性:", property, ' +
            '"  属性类型:", ' + 'typeof property, ' +
            // '"  属性值:", ' + 'target[property], ' +
            '"  属性值类型:", typeof target[property]);\n' +
            '        return target[property];\n' +
            '    },\n' +
            '    set: function(target, property, value, receiver) {\n' +
            '        console.log("方法:", "set  ", "对象:", ' +
            '"' + proxy_array[i] + '" ,' +
            '"  属性:", property, ' +
            '"  属性类型:", ' + 'typeof property, ' +
            // '"  属性值:", ' + 'target[property], ' +
            '"  属性值类型:", typeof target[property]);\n' +
            '        return Reflect.set(...arguments);\n' +
            '    }\n' +
            '}'
        eval('try{\n' + proxy_array[i] + ';\n'
            + proxy_array[i] + '=new Proxy(' + proxy_array[i] + ', ' + handler + ')}catch (e) {\n' + proxy_array[i] + '={};\n'
            + proxy_array[i] + '=new Proxy(' + proxy_array[i] + ', ' + handler + ')}')
    }
}
proxy_array = ['window','document','screen','navigator','hisotry','location']
get_enviroment(proxy_array)
